package com.shen.eduservice.controller;


import com.shen.commonutils.Result;
import com.shen.eduservice.entity.subject.OneSubject;
import com.shen.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author shenkaituo
 * @since 2020-06-19
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

        @Autowired
    EduSubjectService eduSubjectService;
        //添加课程分类 ，获取上传的文件 把文件内容 读取出来
    @PostMapping("addSubject")
    public Result addSubject(MultipartFile file) throws IOException {
        //上传文件
        eduSubjectService.saveSubject(file,eduSubjectService);
        return Result.ok();
    }
    //课程分类的 树形显示
    @GetMapping("getAllSubject")
    public Result getAllSubject(){
        //list集合中的泛型为onesubject
        List<OneSubject> list =eduSubjectService.getALLOneTwoSubject();
        return Result.ok().data("list",list);
    }
}

